package com.eorchis.module.util;

import java.util.ArrayList;
import java.util.List;
import org.apache.poi.hssf.record.formula.functions.T;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;

@SuppressWarnings("unchecked")
public class JsonToT {
	

//	public static final Object parse(String text); // 把JSON文本parse为JSONObject或者JSONArray 
//	public static final JSONObject parseObject(String text)； // 把JSON文本parse成JSONObject    
//	public static final  T parseObject(String text, Class clazz); // 把JSON文本parse为JavaBean 
//	public static final JSONArray parseArray(String text); // 把JSON文本parse成JSONArray 
//	public static final  List parseArray(String text, Class clazz); //把JSON文本parse成JavaBean集合 
//	public static final String toJSONString(Object object); // 将JavaBean序列化为JSON文本 
//	public static final String toJSONString(Object object, boolean prettyFormat); // 将JavaBean序列化为带格式的JSON文本 
//	public static final Object toJSON(Object javaObject); 将JavaBean转换为JSONObject或者JSONArray。
	
	/**
	 * json转bean
	 * */
	@SuppressWarnings({ "rawtypes", "hiding" })
	public static <T>T getPerson(String jsonString, Class cls) {
	        T t = null;
	        try {
	            t = (T)JSON.parseObject(jsonString, cls);
	        } catch (Exception e) {
	            // TODO: handle exception
	        }
	        return t;
	    }
	@SuppressWarnings("rawtypes")
	public static List getPersons(String jsonString, Class cls) {
	        List list = new ArrayList();
	        try {
	            list = JSON.parseArray(jsonString, cls);
	        } catch (Exception e) {
	        }
	        return list;
	    }
	
	/**
	 * json转List
	 * */
	@SuppressWarnings({ "rawtypes", "hiding" })
	public static<List> List listKeyMaps(String jsonString) {
	        List list = (List) new ArrayList();
	        try {
	            list = (List) JSON.parseObject(jsonString,
	                    new TypeReference() {
	            });
	        } catch (Exception e) {
	        }
	        return list;
	    }

}

